#pragma once

#include <iostream>
#include <string>
#include <functional>
#include "Socket.hpp"
#include "InetAddr.hpp"
#include "Logger.hpp"

class Reactor;

using callback_t = std::function<std::string(std::string& inbuffer)>;

class Connection
{
public:
    Connection()
    {
    }
    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;

    int Sockfd()
    {
        return _sockfd;
    }
    void SetEvent(uint32_t events)
    {
        _events = events;
    }
    uint32_t Events() { return _events; }

    void SetAddr(const InetAddr &addr)
    {
        _peer = addr;
    }

    void SetSockfd(int sockfd)
    {
        _sockfd = sockfd;
    }

    Reactor *Owner()
    {
        return _owner;
    }
    void SetOwner(Reactor *r)
    {
        _owner = r;
    }
    void SetCallBack(callback_t cb)
    {
        _cb = cb;
    }
    virtual ~Connection()
    {
    }

protected:
    int _sockfd;
    uint32_t _events;
    std::string _inbuffer; // std::vector<char> inbuffer
    std::string _outbuffer;
    // uint64_t last_time_stamp;

    InetAddr _peer;
    Reactor *_owner; // 回指指针
    callback_t _cb;
};